package com.krisyu.statePattern.sp1;

/**
 * @Author: Kris
 * @Date: 2022/1/9 - 01 - 09 - 22:14
 * @Description: 电梯运行的上下文环境。 持有电梯的所有状态，用于每次行为导致状态的更新，以及通知相应状态下，执行对应操作。
 * @version: 1.0
 */
public class Context {
    //定义出所有的电梯状态
    public final static OpeningState openingState = new OpeningState();
    public final static ClosingState closingState = new ClosingState();
    public final static RunningState runningState = new RunningState();
    public final static StoppingState stoppingState = new StoppingState();

    // 定义一个当前的电梯状态
    private LiftState liftState;

    public void setLiftState(LiftState liftState) {
        this.liftState = liftState;
        // 把当前的环境通知到各个状态的实现类种去
        this.liftState.setContext(this);
    }

    public LiftState getLiftState() {
        return liftState;
    }

    public void run(){
        this.liftState.run();
    }
    public void stop(){
        this.liftState.stop();
    }
    public void open(){
        this.liftState.open();
    }
    public void close(){
        this.liftState.close();
    }
}
